package com.xiaobai.redisContact.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
@Slf4j
public class RedisKeyExpirationEventMessageListener extends KeyExpirationEventMessageListener {

    public RedisKeyExpirationEventMessageListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String expiredKey = message.toString();
        System.out.println(Arrays.toString(pattern));
        log.info("监听到过期key:{}", expiredKey);
    }
}
